package com.zhangxin.designmode.oop.demo1;

/**
 * @author zhangxin
 * @date 2022/4/2
 */
public class SortedDynamicArray extends DynamicArray {
    @Override
    public void add(Integer e) {
        ensureCapacity();
        elements[size] = e;
        for (int i = size - 1; i >= 0; --i) {
            if(elements[i]>e){
                elements[i+1] = elements[i];
                elements[i] = e;
            }else{
                break;
            }
        }
        ++size;
    }
}
